﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#define TIS_CAMERA


#include <QSettings>
#include <QMainWindow>
#include <QScrollArea>
#include <QSpinBox>
#include <QKeyEvent>
#include <QProgressDialog>
#include "DisplayWidget/ToolBarMeasure.h"
#include "DisplayWidget/ToolBarZoom.h"
#include "DisplayWidget/ToolBarProperty.h"

#include "CameraCommon/ToolBarCamera.h"
#include "CameraCommon/CameraImage_RGB24.h"
#include "CameraCommon/CameraImage_RGB32.h"


#ifdef TIS_CAMERA
#include "CameraImagingSource/TisCamera.h"
#endif //TIS_CAMERA


#include "NosepieceCommon/ToolbarNosepiece.h"
#include "NosepieceCommon/LensCompensation.h"
#include "NosepieceOlympusREMCB/NosepieceOlympusREMCB.h"
//#include "NosepieceNikon/NosepieceNikon.h"
#include "StageControlCommon/FastMoveDockWidget.h"
#include "StageControlCommon/StageControlDockWidget.h"

#include "StageControlB140/dmc_b140_m.h"
#include "StageControlB140/StageControl.h"

#include "Joystick/JoyStick2D.h"


namespace Ui {
class MainWindow;
}
class DisplayWidget;
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    enum ZOOM{ LEN0 = 0, LEN1 = 1, LEN2, LEN3, LEN4, LEN5 };
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void clearAllMark();
    QImage getImage();
    void setImage(QImage iamge);
    void setCamera(bool on);
    void getEncodePosition(double encodePos_mm[]);
    void getTheoryPosition(double theoryPos_mm[]);
    double getScale();
    int getLens();
    void setLens(int lens);

    bool setExpoureTime(int value);
    int getExpoureTime();

    void moveToRelativePos(double x_mm, double y_mm, double z_mm, double speed = 5.0);

signals:
    void autoPanelMeasure();
    void RGB24ImageChanged(const uint8_t *pBuf, QSize size);

protected:
    QString configFilePath();
    void closeEvent(QCloseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;  //双击
private:
    void setupToolBar(QSettings &settings);
    void setupScale(QSettings &settings);
    void setupNosepiece(QSettings &settings);
    void setupTisCamera();
    void setupJoyStick(QSettings &settings);
    void setupDMCB140M(QSettings &settings);
    void setupStageControl(QSettings &settings);


private slots:
    void showBatchDialog();
    void loadImage();
    void saveImageWithMark();
    void saveImageWithoutMark();

    void calibrate();

    void showGoHomeDialg();

    /// Camera 相关的 slots
    void selectTisCamera();
    void defaultTisCamera();
    void adjustTisCamera();
    void closeTisCamera();
    void startTisCamera();
    void suspendTisCamera();

    void changeRuler(int old, int len);
    void updatePos();
    void updateIO();
    void lensWDAdjust(int oldLens, int newLens);

protected:
    Ui::MainWindow *ui;
    QScrollArea *m_scrollArea;
    DisplayWidget *m_centerWidget;


    double m_scale[8];
    int m_lens;
    CameraImage * m_cameraImage;
    DShowLibAutoInit m_autoInit;
    TisCamera * m_pTisCamera;

public:
    NosepieceOlympusREMCB *m_nosepiece;

    FastMoveDockWidget * m_pFastMovePad;
    StageControlDockWidget * m_pStageControlPad;
    JoyStick2D * m_pJoyStick;
    StageControl *m_pStageControl;
    DMC_B140_M *m_b140card;
    QTimer *m_timerXYZPos;
    LensCompensation m_lensCompensation;

    double m_theoryPos_mm[4];
    double m_encodePos_mm[4];
    bool m_io[8];
    bool m_isMeasure;

private:
    ToolBarMeasure *m_toolbarMeasure;
    ToolBarZoom *m_toolbarZoom;
    ToolBarProperty *m_toolbarProperty;
    ToolBarCamera *m_toolbarCamera;
    ToolBarNosepiece *m_toolbarNosepiece;
};



#endif // MAINWINDOW_H
